EEL_MODS	+= opensbi

DEPS += opensbi
$(eval $(call deftargets_git,opensbi,SBI))
$(eval $(call deftargets_download,opensbi,SBI,$$(SBI_PKG),v$$(SBI_VERSION)))

PHONY-opensbi += sbi-% opensbi
sbi-%: $(BUILD_DEPS)
	$(MAKE) $(JOB_OPT) \
		-C $(S_SBI_DIR) \
		PLATFORM=$(SBI_PLAT) \
		$(SBI_CFG_OPTS) \
		CROSS_COMPILE=$(TC_PREFIX) \
		O=$(O_SBI_DIR) \
		$(patssbist sbi-%,%,$@)

opensbi: $(BUILD_DEPS) opensbi-prepare $(OPENSBI_DEPS)
	@mkdir -p $(O_SBI_DIR)
	$(MAKE) $(JOB_OPT) \
		-C $(S_SBI_DIR) \
		PLATFORM=$(SBI_PLAT) \
		$(SBI_CFG_OPTS) \
		CROSS_COMPILE=$(TC_PREFIX) \
		O=$(O_SBI_DIR) \
		$(SBI_TARGETS)

$(SBI_ELF) $(SBI_IMAGE):
	@$(MAKE_THIS) opensbi

PHONY-opensbi += opensbi-clean
opensbi-clean:
	\rm -fr $(O_SBI_DIR)

PHONY-opensbi += opensbi-defconfig opensbi-menuconfig opensbi-savedefconfig
opensbi-defconfig: opensbi-prepare sbi-$(SBI_CONFIG)
opensbi-menuconfig: sbi-menuconfig

opensbi-savedefconfig: sbi-savedefconfig
	@mkdir -p $(EEL_CHG_DIR)/$(SBI_VER_DIR)/configs
	cp $(O_SBI_DIR)/defconfig \
		$(EEL_CHG_DIR)/$(SBI_VER_DIR)/configs/$(SBI_SAVECONF)
